<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">
        <el-form-item label="店铺名称" prop="shop_name">
          <el-input v-model="filters.shop_name" placeholder="店铺名称" style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="对账单号" prop="reconciliation_no">
          <el-input v-model="filters.reconciliation_no" placeholder="对账单号" style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="结算对账类型" prop="settle_reconciliation_type">
          <el-select v-model="filters.settle_reconciliation_type" placeholder="结算对账类型">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in settleReconciliationTypeOption"
              :key="item.code"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-popover
            placement="right"
            title="选择商家"
            trigger="click"
            width="800"
            hight="1000"
            v-model="merchantVisible"
          >
            <el-row>
              <el-form-item prop="pay_type" style="float:left;padding-top:10px;padding-left:15px;">
                <el-input v-model="filtersCyTable1.merchant_code" placeholder="商家编码"></el-input>
              </el-form-item>
              <el-form-item lable="商家名称" style="float:left;padding-top:10px;padding-left:15px;">
                <el-input v-model="filtersCyTable1.merchant_name" placeholder="商家名称"></el-input>
              </el-form-item>
              <el-form-item style="float:left;padding-top:10px;padding-left:15px;">
                <kt-button
                  icon="fa fa-search"
                  :label="$t('action.search')"
                  type="primary"
                  @click="resetCyTable1"
                />
              </el-form-item>
              <el-form-item style="float:left;padding-top:10px;padding-left:15px;">
                <kt-button
                  icon="fa fa-refresh" :label="$t('action.reset')"
                  @click="resetCyTable1"
                  type="primary"
                />
              </el-form-item>

              <el-form-item style="float:left;padding-top:10px;padding-left:15px;">
                <kt-button
                  icon="fa fa-hand-pointer-o"
                  :label="$t('action.comfirm')"
                  @click="operationClick"
                  type="primary"
                />
              </el-form-item>
            </el-row>

            <!--表格内容栏-->
            <cy-table1
              :height="1000"
              :data="pageResult"
              :columns="clickColumns"
              @findPage="clinkMock"
              ref="CyTable1"
              :showBatchDelete="false"
              :showDeleteOperation="false"
              :showEditOperation="false"
              :showDetailOperation="false"
              :showOperation="false"
            ></cy-table1>

            <el-input
              slot="reference"
              v-model="filters.merchant_name"
              placeholder="商家名称"
              :disabled="true"
              style="width:200px"
            ></el-input>
          </el-popover>
        </el-form-item>

        <el-form-item label="进退折单号" prop="discount_no" style="margin-left:12px">
          <el-input v-model="filters.discount_no" placeholder="进退折单号" style="width:200px;"></el-input>
        </el-form-item>
        <el-form-item label="单据类型" prop="document_type">
          <el-select v-model="filters.document_type" placeholder="单据类型" style="width:200px">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in documentTypeOption"
              :key="item.code"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结算状态" prop="reconciliation_status">
          <el-select v-model="filters.reconciliation_status" placeholder="结算状态" style="width:200px">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in reconciliationStatusOption"
              :key="item.code"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="进退折日期" prop="advance_date" style="margin-left:15px">
          <el-date-picker
            v-model="filters.advance_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="开始"
            class="input_postion"
             style="width:200px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label prop="retreat_date">
          <el-date-picker
            v-model="filters.retreat_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="结束"
            class="input_postion"
             style="width:200px;margin-right:0px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="商家对账状态" prop="merchant_reconciliation_status">
          <el-select v-model="filters.merchant_reconciliation_status" placeholder="商家对账状态">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in merchantReconciliationStatusOption"
              :key="item.code"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="应付日期" prop="must_pay_start_date">
          <el-date-picker
            v-model="filters.must_pay_start_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="开始"
            class="input_postion"
            style="width:200px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label prop="must_pay_end_date">
          <el-date-picker
            v-model="filters.must_pay_end_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="结束"
            style="margin-right:97px;width:200px"
            class="input_postion"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="到账日期" prop="arrive_start_date">
          <el-date-picker
            v-model="filters.arrive_start_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="开始"
            class="input_postion"
            style="width:200px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label prop="arrive_end_date">
          <el-date-picker
            v-model="filters.arrive_end_date"
            type="date"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            placeholder="结束"
            class="input_postion"
            style="width:200px;margin-right:28px"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="币别名称" prop="currency_code">
          <el-select v-model="filters.currency_code" placeholder="币别名称">
            <el-option label="请选择" value></el-option>
            <el-option
              v-for="item in currencyCodeOption"
              :key="item.code"
              :label="item.label"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item>
          <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
          </el-form-item>
          <el-form-item>
            <kt-button :label="'批量对账'" type="primary" @click="batchRecon" />
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form>
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :width="1000"
      :height="250"
      :data="pageResult"
      :columns="filterColumns"
      :showOperation="false"
      :showEditOperation="false"
      :showBatchDelete="false"
      :showDeleteOperation="false"
      @findPage="findPage"
      ref="CyTable"
    ></cy-table>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput";
import CyTable from "@/views/Core/CyTable";
import CyTable1 from "@/views/Core/CyTable";
import KtButton from "@/views/Core/KtButton";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
export default {
  components: {
    PopupTreeInput,
    CyTable,
    CyTable1,
    KtButton,
    TableColumnFilterDialog
  },
  data() {
    return {
      size: "small",
      filters: {
        shop_name: "",
        reconciliation_no: "",
        discount_no: "",
        settle_reconciliation_type: "",
        reconciliation_status: "",
        document_type: "",
        merchant_reconciliation_status: "",
        advance_date: "",
        retreat_date: "",
        must_pay_start_date: "",
        must_pay_end_date: "",
        arrive_start_date: "",
        arrive_end_date: "",
        currency_code: ""
      },
      settleReconciliationTypeOption: [
        {
          code: "1",
          label: "总部"
        },
        {
          code: "2",
          label: "供应商"
        }
      ],
      currencyCodeOption: [
        {
          code: "1",
          label: "CNY"
        },
        {
          code: "2",
          label: "AUD"
        },
        {
          code: "3",
          label: "GBP"
        },
        {
          code: "4",
          label: "USD"
        }
      ],
      merchantReconciliationStatusOption: [
        {
          code: "1",
          label: "待对账"
        },
        {
          code: "2",
          label: "对账成功"
        },
        {
          code: "3",
          label: "对账失败"
        }
      ],
      reconciliationStatusOption: [
        {
          code: "1",
          label: "未结算-未加入结算单"
        },
        {
          code: "2",
          label: "未结算-已加入结算单"
        },
        {
          code: "3",
          label: "已结算"
        },
        {
          code: "4",
          label: "部分结算"
        }
      ],
      documentTypeOption: [
        {
          code: "1",
          label: "采购收货"
        },
        {
          code: "2",
          label: "采购退货"
        },
        {
          code: "3",
          label: "采购折让"
        }
      ],
      saleChannelOption: [
        {
          code: "1",
          label: "自建B2C"
        },
        {
          code: "2",
          label: "自建B2B"
        },
        {
          code: "3",
          label: "自建O2O"
        },
        {
          code: "4",
          label: "自建POS"
        },
        {
          code: "5",
          label: "分销渠道"
        },
        {
          code: "6",
          label: "天猫"
        },
        {
          code: "7",
          label: "饿了么"
        },
        {
          code: "8",
          label: "美团外卖"
        },
        {
          code: "9",
          label: "京东到家"
        }
      ],
      radio: "1",
      options: {},
      filtersCyTable1: {
        merchant_code: "",
        merchant_name: ""
      },
      columns: [
        { prop: "shop_name", label: "店铺名称", minWidth: 100 },
        { prop: "reconciliation_no", label: "对账单号", minWidth: 100 },
        {
          prop: "settle_reconciliation_type",
          label: "结算对象类型",
          minWidth: 100
        },
        {
          prop: "settle_reconciliation_code",
          label: "结算对象编码",
          minWidth: 100
        },
        {
          prop: "settle_reconciliation_name",
          label: "结算对象名称",
          minWidth: 100
        },
        { prop: "merchant_name", label: "供应商名称", minWidth: 100 },
        { prop: "merchant_code", label: "供应商编码", minWidth: 100 },
        { prop: "document_type", label: "单据类型", minWidth: 100 },
        { prop: "document_name", label: "单据名称", minWidth: 100 },
        { prop: "discount_no", label: "进退折单号", minWidth: 100 },
        { prop: "currency_code", label: "币别", minWidth: 100 },
        { prop: "rate", label: "汇率", minWidth: 100 },
        { prop: "must_pay_amount", label: "应付金额", minWidth: 100 },
        { prop: "discount_date", label: "进退折日期", minWidth: 100 },
        { prop: "must_pay_date", label: "应付日期", minWidth: 100 },
        { prop: "expire_date", label: "到期日期", minWidth: 100 },
        {
          prop: "merchant_reconciliation_status",
          label: "商家对账状态",
          minWidth: 100
        },
        {
          prop: "emerchant_reconciliation_date",
          label: "商家对账时间",
          minWidth: 100
        },
        {
          prop: "emerchant_reconciliation_por",
          label: "商家对账人",
          minWidth: 100
        },
        { prop: "settle_status", label: "结算状态", minWidth: 100 },
        { prop: "settle_no", label: "结算单号", minWidth: 100 },
        { prop: "invoic_status", label: "开票状态", minWidth: 100 }
      ],
      clickColumns: [
        { prop: "merchantId", label: "商家编码", minWidth: 120 },
        { prop: "merchantName", label: "商家名称", minWidth: 120 },
        { prop: "merchantType", label: "商家类型", minWidth: 120 }
      ],
      mockPage: {
        total: "3",
        rows: [
          {
            id: "1",
            shop_name: "王小二BBC店",
            reconciliation_no: "29",
            settle_reconciliation_type: "供应商",
            settle_reconciliation_code: "1909170000040390",
            settle_reconciliation_name: "A供应商",
            document_type: "采购退货",
            discount_date: "2019-10-17",
            document_name: "采购退货单",
            discount_no: "SH1910100000069639",
            merchant_code: "1909170000040390",
            merchant_name: "A供应商",
            currency_code: "USD",
            rate: "0.1476",
            must_pay_amount: "24.80",
            must_pay_date: "2019-10-17",
            expire_date: "2019-12-17",
            merchant_reconciliation_status: "对账成功",
            emerchant_reconciliation_date: "2019-11-14 16:58:43",
            emerchant_reconciliation_por: "merchant",
            settle_status: "已结算",
            settle_no: "1911220014128375",
            invoic_status: "未开票"
          },
          {
            id: "2",
            shop_name: "王小二BBC店",
            reconciliation_no: "29",
            settle_reconciliation_type: "供应商",
            settle_reconciliation_code: "1909170000040390",
            settle_reconciliation_name: "A供应商",
            document_type: "采购退货",
            discount_date: "2019-10-17",
            document_name: "采购退货单",
            discount_no: "SH1910100000069639",
            merchant_code: "1909170000040390",
            merchant_name: "A供应商",
            currency_code: "USD",
            rate: "0.1476",
            must_pay_amount: "24.80",
            must_pay_date: "2019-10-17",
            expire_date: "2019-12-17",
            merchant_reconciliation_status: "对账成功",
            emerchant_reconciliation_date: "2019-11-14 16:58:43",
            emerchant_reconciliation_por: "merchant",
            settle_status: "已结算",
            settle_no: "1911220014128375",
            invoic_status: "未开票"
          },
          {
            id: "3",
            shop_name: "王小二BBC店",
            reconciliation_no: "29",
            settle_reconciliation_type: "供应商",
            settle_reconciliation_code: "1909170000040390",
            settle_reconciliation_name: "A供应商",
            document_type: "采购退货",
            discount_date: "2019-10-17",
            document_name: "采购退货单",
            discount_no: "SH1910100000069639",
            merchant_code: "1909170000040390",
            merchant_name: "A供应商",
            currency_code: "USD",
            rate: "0.1476",
            must_pay_amount: "24.80",
            must_pay_date: "2019-10-17",
            expire_date: "2019-12-17",
            merchant_reconciliation_status: "对账成功",
            emerchant_reconciliation_date: "2019-11-14 16:58:43",
            emerchant_reconciliation_por: "merchant",
            settle_status: "已结算",
            settle_no: "1911220014128375",
            invoic_status: "未开票"
          }
        ]
      },
      clickDetail: {
        rows: [
          {
            merchantId: "300001",
            merchantName: "录屏商家二",
            merchantType: "自营商家"
          },
          {
            merchantId: "300001",
            merchantName: "录屏商家二",
            merchantType: "自营商家"
          }
        ],
        total: 1,
        code: "0000"
      },

      filterColumns: [],
      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {},

      operation: false, // true:新增, false:编辑
      dialogVisible: false,
      detailDialogVisible: false, // 新增编辑界面是否显示
      merchantVisible: false,
      editLoading: false
    };
  },
  methods: {
    // 获取分页数据
    findPage: function(data) {
      this.$refs.CyTable.findPageMock(this.mockPage);
    },
    clinkMock: function() {
      this.$refs.CyTable1.findPageMock(this.clickDetail);
    },
    operationClick: function() {
      var this_ = this;
      this_.filters.merchant_name = "录屏商家二";
      this_.merchantVisible = false;
    },
    resetCyTable1: function() {
      this.filtersCyTable1 = {};
      this.clinkMock();
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },
    // 编辑
    batchRecon: function() {
      this.$refs.CyTable.batchOperationMock("对账成功");
    },
    // 批量删除
    handleDelete: function(data) {
      var this_ = this;
      this_.$message({ message: "操作成功", type: "success" });
    },
    // 处理表格列过滤显示
    displayFilterColumnsDialog: function() {
      this.$refs.tableColumnFilterDialog.setDialogVisible(true);
    },
    // 处理表格列过滤显示
    handleFilterColumns: function(data) {
      this.filterColumns = data.filterColumns;
      this.$refs.tableColumnFilterDialog.setDialogVisible(false);
    },
    // 处理表格列过滤显示
    initColumns: function() {
      var temp = [];

      $.each(this.columns, function(key, val) {
        temp.push(val);
      });
      this.filterColumns = temp;
    },
    //列表下载
    downloadExcel() {
      this.$confirm("确定下载列表文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let filename = "系统参数下载";
          this.$refs.CyTable.exportData(
            this.filters,
            this.filterColumns,
            filename
          );
        })
        .catch(() => {});
    }
  },

  mounted() {
    this.initColumns();
  }
};
</script>

<style scoped>
</style>
